package screens 
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	/**
	 * ...
	 * @author Andy Wolff
	 */
	public class InstrumentScreen extends Screen
	{
		private var main:Main;
		
		private	var panel:MovieClip = new MovieClip();
		private	var windBtn:MovieClip = new MovieClip();
		private	var brassBtn:MovieClip = new MovieClip();
		private	var fluteBtn:MovieClip = new MovieClip();
		private	var oboeBtn:MovieClip = new MovieClip();
		private	var trumpetBtn:MovieClip = new MovieClip();
		private	var selectLine:MovieClip = new MovieClip();
		private	var selectLine2:MovieClip = new MovieClip();
		
		
		[Embed(source = '../images/Buttons/songmaker.png')] private var spacerimg:Class;
		
		[Embed(source = '../images/newsong.png')] private var newsongimg:Class;
		[Embed(source = '../images/Buttons/chooseInstrument.png')] private var titleimg:Class;
		[Embed(source = '../images/Buttons/back.png')] private var backimg:Class;
		[Embed(source = '../images/Buttons/continue.png')] private var continueimg:Class;
		
		
		[Embed(source = '../images/Buttons/brass.png')] private var brassimg:Class;
		[Embed(source = '../images/Buttons/wind.png')] private var windimg:Class;
		[Embed(source = '../images/Buttons/flute.png')] static public var fluteimg:Class;
		[Embed(source = '../images/Buttons/trumpet.png')] static public var trumpetimg:Class;
		[Embed(source = '../images/Buttons/oboe.png')] static public var oboeimg:Class;
		[Embed(source = '../images/Buttons/instruments1.png')] private var instrumentsPanelimg:Class;
		[Embed(source = '../images/Buttons/instrumentsSelect.png')] private var selectionimg:Class;
				
		public function InstrumentScreen(main:Main) 
		{
			this.main = main;
			super();
			graphics.beginFill(0x555555, 1);
			graphics.drawRect(0, 0, 800, 470);
			graphics.endFill();
			main.stage.addEventListener(KeyboardEvent.KEY_DOWN, this.keypressed);
			
			
			//Used for spacing buttons consistently across screens
			var spacer:MovieClip = new MovieClip();
			spacer.addChild(new spacerimg())
			Main.center(spacer);
			spacer.y = 20;
			
			//Title of the screen
			var title:MovieClip = new MovieClip();
			title.addChild(new titleimg())
			Main.center(title);
			title.y = 20;
			addChild(title);
			
			//Box around instruments to select
			panel.addChild(new instrumentsPanelimg())
			Main.center(panel);
			addChild(panel);
			
			//The highlight on the category of instrument
			selectLine.addChild(new selectionimg())
			Main.center(selectLine);
			selectLine.x -= 110;
			selectLine.y -= 100;
			addChild(selectLine);
			
			//The highlight on the selected instrument
			selectLine2.addChild(new selectionimg())
			Main.center(selectLine2);
			selectLine2.x += 105;
			selectLine2.y -= 100;
			addChild(selectLine2);
			
			//The button for Wind instruments
			windBtn.addChild(new windimg());
			Main.center(windBtn);
			windBtn.x -= 160;
			windBtn.y -= 100;
			addChild(windBtn);
			windBtn.addEventListener(MouseEvent.CLICK, click_wind);
			
			//The button for Brass instruments
			brassBtn.addChild(new brassimg());
			Main.center(brassBtn);
			brassBtn.x = windBtn.x;
			brassBtn.y = windBtn.y + windBtn.height + 10;
			addChild(brassBtn);
			brassBtn.addEventListener(MouseEvent.CLICK, click_brass);
			
			
			//The button for the oboe
			oboeBtn.addChild(new oboeimg());
			Main.center(oboeBtn);
			oboeBtn.x += 160;
			oboeBtn.y -= 100;
			addChild(oboeBtn);
			oboeBtn.addEventListener(MouseEvent.CLICK, click_oboe);
			
			//The button for the flute
			fluteBtn.addChild(new fluteimg());
			fluteBtn.x = oboeBtn.x;
			fluteBtn.y = oboeBtn.y + oboeBtn.height + 10;
			addChild(fluteBtn);
			fluteBtn.addEventListener(MouseEvent.CLICK, click_flute);
			
			//The button for the trumpet
			trumpetBtn.addChild(new trumpetimg());
			Main.center(trumpetBtn);
			trumpetBtn.x += 10000;
			trumpetBtn.y -= 100;
			addChild(trumpetBtn);
			
			//Back button
			var backBtn:MovieClip = new MovieClip();
			backBtn.addChild(new backimg());
			Main.center(backBtn);
			backBtn.y = spacer.y + spacer.height + 280;
			backBtn.x -= 225;
			addChild(backBtn);
			backBtn.addEventListener(MouseEvent.CLICK, click_back);
			
			//Continue button
			var continueBtn:MovieClip = new MovieClip();
			continueBtn.addChild(new continueimg());
			Main.center(continueBtn);
			continueBtn.y = backBtn.y;
			continueBtn.x = backBtn.x + 400;
			addChild(continueBtn);
			continueBtn.addEventListener(MouseEvent.CLICK, click_continue);
			
		}
		
		public function keypressed(e:KeyboardEvent):void {
			//press enter (for keycodes, see: http://www.dakmm.com/?p=272 )
			if (e.charCode==13) main.switchScreen(new MainScreen(main));
		}
		
		public function click_wind(me:MouseEvent):void {
			
			selectLine.y = windBtn.y;
			
			Main.center(oboeBtn);
			oboeBtn.x += 160;
			oboeBtn.y -= 100;
			
			
			fluteBtn.x = oboeBtn.x;
			fluteBtn.y = oboeBtn.y + oboeBtn.height + 10;
			
			
			trumpetBtn.x = 10000;
			
			
		}
		
		
		public function click_brass(me:MouseEvent):void {
			
			selectLine.y = windBtn.y + windBtn.height + 10;
			
			selectLine2.y = windBtn.y;
			
			oboeBtn.x = 10000;
			fluteBtn.x = 10000;
			
			Main.center(trumpetBtn);
			trumpetBtn.x += 130;
			trumpetBtn.y -= 95;
			
		}
		
		
		public function click_flute(me:MouseEvent):void {
			
			selectLine2.y = fluteBtn.y;
		}
		
		
		public function click_oboe(me:MouseEvent):void {
			
			selectLine2.y = windBtn.y;
			
		}
		
		public function click_back(me:MouseEvent):void {
			main.switchScreen(new NewSongScreen(main));
		}
		
		public function click_continue(me:MouseEvent):void {
			main.switchScreen(new ScaleScreen(main));
		}
		
		
		override public function end():void 
		{
			main.stage.removeEventListener(KeyboardEvent.KEY_DOWN, this.keypressed);
		}
		
	}

}